home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
BCI NET
/
BCI NET Dec 94.iso
/
archives
/
telecomm
/
bbs
/
maxsdoors2.lha
/
TopDL10.lha
/
topdl.p
< prev
next >
Wrap
Text File
|
1993-12-21
|
5KB
|
218 lines
Program TopDL;
{
Program will list each record and either (i) edit one member of the
linked list or (ii) append a new entry to the linked list. The linked
list will resemble a quicksort tree for speed.
}
{$I "Include:Utils/StringLib.i"}
{$O-} { turn off IO error checking }
const
StdInName : String = NIL;
StdOutName : String = NIL;
filecount : integer = 0;
type
llisttype = record
filename : string;
count : integer;
nextup,
nextdn : ^llisttype
end;
llistptrtype = ^llisttype;
var
output_file,
input_file : text;
fname : string;
mychar : char;
thelist : llistptrtype;
top10array : array [1..10] of llistptrtype;
counter,
counter2 : short;
{***************************************************************************}
{****************************** FUNCTION CALLS *****************************}
{***************************************************************************}
function ucase(anystring:string):string;
var
tmparray : array [0..32] of char;
tmpstring : string;
begin
tmpstring := adr(tmparray);
for counter := 0 to strlen(anystring)-1 do
tmpstring[counter] := toupper(anystring[counter]);
tmpstring[counter+1] := '\0';
ucase := strdup(tmpstring)
end;
{***************************************************************************}
function add_dl(alist:llistptrtype):llistptrtype;
{
adds download entry to the linked list
}
begin
inc(filecount);
if alist=NIL then begin
new(alist);
alist^.filename := strdup(fname);
alist^.count := 1;
alist^.nextup := NIL;
alist^.nextdn := NIL;
add_dl := alist
end;
if strcmp(ucase(alist^.filename),ucase(fname))=0 then begin
inc(alist^.count);
add_dl := alist
end;
if strcmp(ucase(alist^.filename),ucase(fname))<0 then begin
alist^.nextup := add_dl(alist^.nextup);
add_dl := alist
end;
if strcmp(ucase(alist^.filename),ucase(fname))>0 then begin
alist^.nextdn := add_dl(alist^.nextdn);
add_dl := alist
end
end;
{***************************************************************************}
function find_top_n(number:short):llistptrtype;
{
finds first top count of downloads excluding top10array[n-1],
top10array[n-2],...,top10array[1] and returns a pointer to that record
}
function traverse(listhead,topptr:llistptrtype):llistptrtype;
{
traverses the full tree and returns the entry with the number'th highest
count
}
function notused(tmpptr:llistptrtype):boolean;
{
checks to see if the given pointer is the same as any of the above
top10array[] pointers
}
begin
for counter2 := 1 to number-1 do
if tmpptr=top10array[counter2] then
notused := FALSE;
notused := TRUE
end;
begin
if listhead=NIL then
traverse := topptr;
topptr := traverse(listhead^.nextdn,topptr);
if ((topptr=NIL) or (listhead^.count>topptr^.count))
and notused(listhead) then
topptr := listhead;
traverse := traverse(listhead^.nextup,topptr);
end;
begin
find_top_n := traverse(thelist,NIL)
end;
{***************************************************************************}
procedure displayit;
{
displays the information as an ANSI output screen - paragon style...
}
begin
counter := 1;
counter2 := 1;
if open("bbs:text/topdl.text",output_file) then begin
if reopen("doors:topdl/topdl.text",input_file) then begin
while not eof(input_file) do begin
write(output_file,input_file^);
read(input_file,mychar)
end;
close(input_file)
end;
if reopen("doors:topdl/topdl.upd",input_file) then begin
while not eof(input_file) do begin
if input_file^='%' then begin
if top10array[counter]=NIL then
write(output_file,'Cnone')
else begin
case strlen(top10array[counter]^.filename) of
1..23 : write(output_file,'',16-(strlen(top10array[counter]^.filename) shr 1),'C');
24,25 : write(output_file,' ');
26,27 : write(output_file,' ');
28,29 : write(output_file,' ');
30,31 : write(output_file,' ');
end;
write(output_file,top10array[counter]^.filename);
end;
inc(counter)
end else if input_file^='&' then begin
if top10array[counter2]=NIL then
write(output_file,' 0')
else
write(output_file,top10array[counter2]^.count:4);
inc(counter2)
end else
write(output_file,input_file^);
read(input_file,mychar)
end;
close(input_file)
end;
write(output_file,'%Z');
close(output_file)
end
end;
{***************************************************************************}
{******************************* MAIN PROGRAM ******************************}
{***************************************************************************}
begin
fname := allocstring(32);
if reopen("bbs:logfiles/dnloadlog.text",input_file) then begin
while not eof(input_file) do begin
if input_file^ <> 'N' then
readln(input_file)
else begin
for counter := 1 to 9 do
repeat
read(input_file,mychar)
until mychar=' ';
readln(input_file,fname);
counter := -1;
repeat
inc(counter);
if fname[counter]=',' then
fname[counter] := '\0'
until fname[counter]='\0';
thelist := add_dl(thelist)
end;
end;
close(input_file);
for counter := 1 to 10 do
if counter>filecount then
top10array[counter] := NIL
else
top10array[counter] := find_top_n(counter);
displayit
end else
writeln('* COULD NOT OPEN bbs:logfiles/dnloadlog.text')
end.